//
//  GKTransactionPasswordView.m
//  jinwan
//
//  Created by 王尧 on 2017/6/7.
//  Copyright © 2017年 wy. All rights reserved.
//

#import "GKTransactionPasswordView.h"

@interface GKTransactionPasswordView ()

@end

@implementation GKTransactionPasswordView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:self.errorLable];
        [self addSubview:self.passwordTF];
        [self addSubview:self.advanceMoneyLable];
        [self addSubview:self.forgetPasswordButton];
    
        [self createConstraints];
        [self addNotification];
    }
    return self;
}

#pragma mark ---- Constraints ----
- (void)createConstraints
{
    [self.errorLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
    }];
    
    [self.passwordTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.errorLable.mas_bottom).offset(6);
        make.height.equalTo(@32);
    }];
    
    NSArray *array = @[self.advanceMoneyLable, self.forgetPasswordButton];
    
    [array mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:0 tailSpacing:0];
    [array mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.passwordTF.mas_bottom).offset(5);
        make.bottom.equalTo(self.mas_bottom).offset(-6);
    }];
}

#pragma mark -- notice --

- (void)addNotification
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChange:) name:UITextFieldTextDidChangeNotification object:self.passwordTF];
}

- (void)textFieldDidChange:(NSNotification *)noti
{
    self.errorLable.text = @"";
}

#pragma mark ---- 忘记密码 ----
- (void)forgetPassword:(UIButton *)sender
{
    if (self.forgetBlock) {
        self.forgetBlock();
    }
}

#pragma mark ---- getter ----
- (UILabel *)errorLable
{
    if (!_errorLable) {
        _errorLable = [[UILabel alloc] init];
        _errorLable.textColor = [UIColor redColor];
        _errorLable.font = [UIFont systemFontOfSize:10];
        //_errorLable.text = @"此处为错误提示框";
    }
    return _errorLable;
}

- (UITextField *)passwordTF
{
    if (!_passwordTF) {
        _passwordTF = [[UITextField alloc] init];
        _passwordTF.borderStyle = UITextBorderStyleRoundedRect;
        _passwordTF.font = [UIFont systemFontOfSize:13];
        _passwordTF.placeholder = @"请输入交易密码";
        _passwordTF.secureTextEntry = YES;
    }
    return _passwordTF;
}

- (UILabel *)advanceMoneyLable
{
    if (!_advanceMoneyLable) {
        _advanceMoneyLable = [[UILabel alloc] init];
        _advanceMoneyLable.textColor = [UIColor black_666666];
        _advanceMoneyLable.font = [UIFont systemFontOfSize:12];
        //_advanceMoneyLable.text = @"提现 2000000元";
    }
    return _advanceMoneyLable;
}

- (UIButton *)forgetPasswordButton
{
    if (!_forgetPasswordButton) {
        _forgetPasswordButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_forgetPasswordButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        _forgetPasswordButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [_forgetPasswordButton setTitle:@"忘记密码？" forState:UIControlStateNormal];
        _forgetPasswordButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _forgetPasswordButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        [_forgetPasswordButton addTarget:self action:@selector(forgetPassword:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _forgetPasswordButton;
}

@end
